package tddd24.ajgallery.shared;


import java.io.BufferedReader;
import java.io.InputStreamReader;

public class scriptRunner {
	
	private Runtime r;
	private Process p;
	
	public scriptRunner(){
		r = Runtime.getRuntime();
	}
	
//	public void run(String command){
//		Jep jep = new Jep(true, SCRIPT_PATH);
//		jep.set("query", query);
//		jep.runScript(command);
//		jep.close();
//	}
//	
	
	public void run(String command, String res){
		 try
	        {            
	            p = r.exec(command);
	            p.waitFor();
	            BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
	            while (br.ready())
	            	res = res.concat(br.readLine());	          
	        }
	        catch (Exception e)
	        {
				String cause = e.getMessage();
				if (cause.equals("python: not found"))
					System.out.println("No python interpreter found.");
				res = "error";
	        }
		 
	}
}
